<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\Database\Model\SoftDeletes;
/**
 * @property int $id 节点ID
 * @property string $title 表单名称
 * @property string $name 表单标识
 * @property string $config 表单配置
 * @property string $field_list 字段数据
 * @property string $remark 备注说明
 * @property int $status 状态
 * @property \Carbon\Carbon $updated_at 更新时间
 * @property \Carbon\Carbon $created_at 创建时间
 * @property string $deleted_at 软删除
 */
class Form extends BaseModel
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'forms';
    protected $hidden = ['deleted_at'];
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['id', 'title', 'name', 'config', 'field_list', 'remark', 'status', 'updated_at', 'created_at', 'deleted_at'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'int', 'status' => 'integer', 'updated_at' => 'datetime', 'created_at' => 'datetime'];
    /**
     * @param  string  $value
     * @return void
     */
    public function setNameAttribute($value)
    {
        $this->attributes['name'] = str_replace('/', '_', $value);
    }
    /**
     * @param  string  $value
     * @return void
     */
    public function getNameAttribute($value)
    {
        return str_replace('_', '/', $value);
    }
    /**
     * @param  string  $value
     * @return void
     */
    public function setFieldListAttribute($value)
    {
        $this->attributes['field_list'] = json_encode($value,JSON_UNESCAPED_UNICODE);
    }
    /**
     * @param  string  $value
     * @return void
     */
    public function setConfigAttribute($value)
    {
        $this->attributes['config'] = json_encode($value,JSON_UNESCAPED_UNICODE);
    }
    /**
     * @param  string  $value
     * @return void
     */
    public function getFieldListAttribute($value)
    {
        return !empty($value)?json_decode($value,true):'';
    }
    /**
     * @param  string  $value
     * @return void
     */
    public function getConfigAttribute($value)
    {
        return !empty($value)?json_decode($value,true):'';
    }

}